<?php


/**
 * Base class that represents a query for the 'w_lp_vv_WizJedn' table.
 *
 *
 *
 * @method LpUnitsQuery orderById($order = Criteria::ASC) Order by the ID_JEDN column
 * @method LpUnitsQuery orderByParentId($order = Criteria::ASC) Order by the ID_NAD_JEDN column
 * @method LpUnitsQuery orderBySupervisorLogoId($order = Criteria::ASC) Order by the NR_OS_KIER column
 * @method LpUnitsQuery orderByNamePl($order = Criteria::ASC) Order by the NAZWA_JEDN column
 * @method LpUnitsQuery orderByNameEn($order = Criteria::ASC) Order by the NAZWA_JEDN_ANG column
 *
 * @method LpUnitsQuery groupById() Group by the ID_JEDN column
 * @method LpUnitsQuery groupByParentId() Group by the ID_NAD_JEDN column
 * @method LpUnitsQuery groupBySupervisorLogoId() Group by the NR_OS_KIER column
 * @method LpUnitsQuery groupByNamePl() Group by the NAZWA_JEDN column
 * @method LpUnitsQuery groupByNameEn() Group by the NAZWA_JEDN_ANG column
 *
 * @method LpUnitsQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method LpUnitsQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method LpUnitsQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method LpUnitsQuery leftJoinUnitsRelatedByParentId($relationAlias = null) Adds a LEFT JOIN clause to the query using the UnitsRelatedByParentId relation
 * @method LpUnitsQuery rightJoinUnitsRelatedByParentId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UnitsRelatedByParentId relation
 * @method LpUnitsQuery innerJoinUnitsRelatedByParentId($relationAlias = null) Adds a INNER JOIN clause to the query using the UnitsRelatedByParentId relation
 *
 * @method LpUnitsQuery leftJoinUnitsRelatedById($relationAlias = null) Adds a LEFT JOIN clause to the query using the UnitsRelatedById relation
 * @method LpUnitsQuery rightJoinUnitsRelatedById($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UnitsRelatedById relation
 * @method LpUnitsQuery innerJoinUnitsRelatedById($relationAlias = null) Adds a INNER JOIN clause to the query using the UnitsRelatedById relation
 *
 * @method LpUnitsQuery leftJoinEmployeesPositions($relationAlias = null) Adds a LEFT JOIN clause to the query using the EmployeesPositions relation
 * @method LpUnitsQuery rightJoinEmployeesPositions($relationAlias = null) Adds a RIGHT JOIN clause to the query using the EmployeesPositions relation
 * @method LpUnitsQuery innerJoinEmployeesPositions($relationAlias = null) Adds a INNER JOIN clause to the query using the EmployeesPositions relation
 *
 * @method LpUnits findOne(PropelPDO $con = null) Return the first LpUnits matching the query
 * @method LpUnits findOneOrCreate(PropelPDO $con = null) Return the first LpUnits matching the query, or a new LpUnits object populated from the query conditions when no match is found
 *
 * @method LpUnits findOneById(string $ID_JEDN) Return the first LpUnits filtered by the ID_JEDN column
 * @method LpUnits findOneByParentId(string $ID_NAD_JEDN) Return the first LpUnits filtered by the ID_NAD_JEDN column
 * @method LpUnits findOneBySupervisorLogoId(string $NR_OS_KIER) Return the first LpUnits filtered by the NR_OS_KIER column
 * @method LpUnits findOneByNamePl(string $NAZWA_JEDN) Return the first LpUnits filtered by the NAZWA_JEDN column
 * @method LpUnits findOneByNameEn(string $NAZWA_JEDN_ANG) Return the first LpUnits filtered by the NAZWA_JEDN_ANG column
 *
 * @method array findById(string $ID_JEDN) Return LpUnits objects filtered by the ID_JEDN column
 * @method array findByParentId(string $ID_NAD_JEDN) Return LpUnits objects filtered by the ID_NAD_JEDN column
 * @method array findBySupervisorLogoId(string $NR_OS_KIER) Return LpUnits objects filtered by the NR_OS_KIER column
 * @method array findByNamePl(string $NAZWA_JEDN) Return LpUnits objects filtered by the NAZWA_JEDN column
 * @method array findByNameEn(string $NAZWA_JEDN_ANG) Return LpUnits objects filtered by the NAZWA_JEDN_ANG column
 *
 * @package    propel.generator.lp.om
 */
abstract class LpBaseUnitsQuery extends ModelCriteria
{
    /**
     * Initializes internal state of LpBaseUnitsQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'vw_lp', $modelName = 'LpUnits', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new LpUnitsQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     LpUnitsQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return LpUnitsQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof LpUnitsQuery) {
            return $criteria;
        }
        $query = new LpUnitsQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   LpUnits|LpUnits[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = LpUnitsPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(LpUnitsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return   LpUnits A model object, or null if the key is not found
     * @throws   PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT ID_JEDN, ID_NAD_JEDN, NR_OS_KIER, NAZWA_JEDN, NAZWA_JEDN_ANG FROM w_lp_vv_WizJedn WHERE ID_JEDN = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_STR);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new LpUnits();
            $obj->hydrate($row);
            LpUnitsPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return LpUnits|LpUnits[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|LpUnits[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(LpUnitsPeer::ID_JEDN, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(LpUnitsPeer::ID_JEDN, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the ID_JEDN column
     *
     * Example usage:
     * <code>
     * $query->filterById('fooValue');   // WHERE ID_JEDN = 'fooValue'
     * $query->filterById('%fooValue%'); // WHERE ID_JEDN LIKE '%fooValue%'
     * </code>
     *
     * @param     string $id The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterById($id = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($id)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $id)) {
                $id = str_replace('*', '%', $id);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(LpUnitsPeer::ID_JEDN, $id, $comparison);
    }

    /**
     * Filter the query on the ID_NAD_JEDN column
     *
     * Example usage:
     * <code>
     * $query->filterByParentId('fooValue');   // WHERE ID_NAD_JEDN = 'fooValue'
     * $query->filterByParentId('%fooValue%'); // WHERE ID_NAD_JEDN LIKE '%fooValue%'
     * </code>
     *
     * @param     string $parentId The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterByParentId($parentId = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($parentId)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $parentId)) {
                $parentId = str_replace('*', '%', $parentId);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(LpUnitsPeer::ID_NAD_JEDN, $parentId, $comparison);
    }

    /**
     * Filter the query on the NR_OS_KIER column
     *
     * Example usage:
     * <code>
     * $query->filterBySupervisorLogoId('fooValue');   // WHERE NR_OS_KIER = 'fooValue'
     * $query->filterBySupervisorLogoId('%fooValue%'); // WHERE NR_OS_KIER LIKE '%fooValue%'
     * </code>
     *
     * @param     string $supervisorLogoId The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterBySupervisorLogoId($supervisorLogoId = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($supervisorLogoId)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $supervisorLogoId)) {
                $supervisorLogoId = str_replace('*', '%', $supervisorLogoId);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(LpUnitsPeer::NR_OS_KIER, $supervisorLogoId, $comparison);
    }

    /**
     * Filter the query on the NAZWA_JEDN column
     *
     * Example usage:
     * <code>
     * $query->filterByNamePl('fooValue');   // WHERE NAZWA_JEDN = 'fooValue'
     * $query->filterByNamePl('%fooValue%'); // WHERE NAZWA_JEDN LIKE '%fooValue%'
     * </code>
     *
     * @param     string $namePl The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterByNamePl($namePl = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($namePl)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $namePl)) {
                $namePl = str_replace('*', '%', $namePl);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(LpUnitsPeer::NAZWA_JEDN, $namePl, $comparison);
    }

    /**
     * Filter the query on the NAZWA_JEDN_ANG column
     *
     * Example usage:
     * <code>
     * $query->filterByNameEn('fooValue');   // WHERE NAZWA_JEDN_ANG = 'fooValue'
     * $query->filterByNameEn('%fooValue%'); // WHERE NAZWA_JEDN_ANG LIKE '%fooValue%'
     * </code>
     *
     * @param     string $nameEn The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function filterByNameEn($nameEn = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($nameEn)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $nameEn)) {
                $nameEn = str_replace('*', '%', $nameEn);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(LpUnitsPeer::NAZWA_JEDN_ANG, $nameEn, $comparison);
    }

    /**
     * Filter the query by a related LpUnits object
     *
     * @param   LpUnits|PropelObjectCollection $units The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   LpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUnitsRelatedByParentId($units, $comparison = null)
    {
        if ($units instanceof LpUnits) {
            return $this
                ->addUsingAlias(LpUnitsPeer::ID_NAD_JEDN, $units->getId(), $comparison);
        } elseif ($units instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(LpUnitsPeer::ID_NAD_JEDN, $units->toKeyValue('PrimaryKey', 'Id'), $comparison);
        } else {
            throw new PropelException('filterByUnitsRelatedByParentId() only accepts arguments of type LpUnits or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UnitsRelatedByParentId relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function joinUnitsRelatedByParentId($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UnitsRelatedByParentId');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UnitsRelatedByParentId');
        }

        return $this;
    }

    /**
     * Use the UnitsRelatedByParentId relation Units object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   LpUnitsQuery A secondary query class using the current class as primary query
     */
    public function useUnitsRelatedByParentIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinUnitsRelatedByParentId($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UnitsRelatedByParentId', 'LpUnitsQuery');
    }

    /**
     * Filter the query by a related LpUnits object
     *
     * @param   LpUnits|PropelObjectCollection $units  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   LpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUnitsRelatedById($units, $comparison = null)
    {
        if ($units instanceof LpUnits) {
            return $this
                ->addUsingAlias(LpUnitsPeer::ID_JEDN, $units->getParentId(), $comparison);
        } elseif ($units instanceof PropelObjectCollection) {
            return $this
                ->useUnitsRelatedByIdQuery()
                ->filterByPrimaryKeys($units->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByUnitsRelatedById() only accepts arguments of type LpUnits or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UnitsRelatedById relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function joinUnitsRelatedById($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UnitsRelatedById');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UnitsRelatedById');
        }

        return $this;
    }

    /**
     * Use the UnitsRelatedById relation Units object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   LpUnitsQuery A secondary query class using the current class as primary query
     */
    public function useUnitsRelatedByIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinUnitsRelatedById($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UnitsRelatedById', 'LpUnitsQuery');
    }

    /**
     * Filter the query by a related LpEmployeesPositions object
     *
     * @param   LpEmployeesPositions|PropelObjectCollection $employeesPositions  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   LpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByEmployeesPositions($employeesPositions, $comparison = null)
    {
        if ($employeesPositions instanceof LpEmployeesPositions) {
            return $this
                ->addUsingAlias(LpUnitsPeer::ID_JEDN, $employeesPositions->getUnitId(), $comparison);
        } elseif ($employeesPositions instanceof PropelObjectCollection) {
            return $this
                ->useEmployeesPositionsQuery()
                ->filterByPrimaryKeys($employeesPositions->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByEmployeesPositions() only accepts arguments of type LpEmployeesPositions or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the EmployeesPositions relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function joinEmployeesPositions($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('EmployeesPositions');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'EmployeesPositions');
        }

        return $this;
    }

    /**
     * Use the EmployeesPositions relation EmployeesPositions object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   LpEmployeesPositionsQuery A secondary query class using the current class as primary query
     */
    public function useEmployeesPositionsQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinEmployeesPositions($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'EmployeesPositions', 'LpEmployeesPositionsQuery');
    }

    /**
     * Exclude object from result
     *
     * @param   LpUnits $units Object to remove from the list of results
     *
     * @return LpUnitsQuery The current query, for fluid interface
     */
    public function prune($units = null)
    {
        if ($units) {
            $this->addUsingAlias(LpUnitsPeer::ID_JEDN, $units->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
